package org.noote.libs.robot.ai;

import java.util.ArrayList;

public class Behaviour {

	protected float _personalclose_distance = 20;
	protected float _curiosity_distance = 60;
			
	protected float _fHappyAngry = 0;
	protected float _fCoolFear = 0;
	protected float _fCuriosityBoring = 0;
	
	enum BehaviourType {BAMBI, PREY, PREDATOR};
	
	protected BehaviourType _iBehaviourType = BehaviourType.BAMBI;
	
	ArrayList<Thing> _knownThings = new ArrayList<Thing>(); 
	
	ArrayList<Thing> _friendThings = new ArrayList<Thing>();
	ArrayList<Thing> _ennemyThings = new ArrayList<Thing>();
	
	public Behaviour()
	{
	}
	
	public void addCool(float fScale)
	{
		_fCoolFear += fScale;
	}
	public void addFear(float fScale)
	{
		_fCoolFear -= fScale;
	}
	
	public void addHappy(float fScale)
	{
		_fHappyAngry += fScale;
	}
	public void addAngry(float fScale)
	{
		_fHappyAngry -= fScale;
	}
	
	public void addCuriosity(float fScale)
	{
		_fCuriosityBoring += fScale;
	}
	public void addBoring(float fScale)
	{
		_fCuriosityBoring -= fScale;
	}

	public void neutralCoolFear(float fScale)
	{
		_fCoolFear += _fCoolFear*fScale;
	}
	public void neutralHappyAngry(float fScale)
	{
		_fHappyAngry += _fHappyAngry*fScale;
	}
	public void neutralCuriosityBoring(float fScale)
	{
		_fCuriosityBoring += _fCuriosityBoring*fScale;
	}
	
	public void action(Thing oThing, float fDistance, float fTimeSlice)
	{
		boolean knowThis = _knownThings.contains(oThing);
		if(!knowThis)
		{
			_knownThings.add(0, oThing); // new thing on top of list !
			knowThis = true;
		}
		
		if(_iBehaviourType == BehaviourType.PREDATOR)
		{
			// TODO
		}
		else if(_iBehaviourType == BehaviourType.PREY)
		{
			// TODO
		}
		else
		{
			if(fDistance < _personalclose_distance)
			{
				addFear(fTimeSlice*1.0f);
				addAngry(fTimeSlice*1.0f);
			}
			else if(fDistance < _curiosity_distance)
			{
				addCuriosity(fTimeSlice*1.0f);
			}
		}
	}
	
	public void step(float fTimeSlice)
	{
		neutralCoolFear(fTimeSlice*0.1f);
		neutralHappyAngry(fTimeSlice*0.1f);
		neutralCuriosityBoring(fTimeSlice*0.1f);
	}
}
